package com.zzh.base

import com.zzh.net.Net
import com.zzh.net.net.NetServer
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type


abstract class BaseModel<T> {
    var api: T? = null

    @Deprecated("使用apiService作为主键，该参数废弃")
    protected open fun getHostType(): Int {
        return 0
    }

    init {
        initApi(getHostType())
    }

    fun initApi(hostType: Int) {
        val type: Type? = javaClass.genericSuperclass
        if (type is ParameterizedType) {
            val clz = type.actualTypeArguments[0]
            if (clz is Class<*>) {
                val clazz = clz as Class<out NetServer>
                api = Net.getNetRetrofitManager().newServer(clazz) as T
            }
        }
    }

}